﻿/**
 *       Project: ServerLib
 *     Copyright: Copyright (C) 2008, Rob Kennedy
 *   Create Date: 2008-07-15 3:40 PM
 * Modified Date: 2008-07-15 3:40 PM    RK  Added comments
 *      Comments: Ignore SA1633.
 *      
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace ServerLib.Plugin
{
    using System.Collections.Generic;
    using ServerLib.Security;
    using ServerLib.Network;

    /// <summary>
    /// Interface Plugin Type Enumeration
    /// </summary>
    public enum PluginType
    {
        /// <summary>
        /// Plugin executes after a socket connection
        /// e.g. Ip blocking check, etc.
        /// </summary>
        Connection = 0,

        /// <summary>
        /// Plugin executes for authentication purposes.
        /// e.g. non-standard authentication protocol.
        /// </summary>
        Authenticator,

        /// <summary>
        /// Plugin executes to validate a message.
        /// e.g. anti-spam, address validation, etc.
        /// </summary>
        Validator,

        /// <summary>
        /// Plugin executes to process a message.
        /// e.g. anti-spam, anti-virus, etc.
        /// </summary>
        Processor,

        /// <summary>
        /// Plugin executes after a socket disconnect.
        /// e.g. Client update, cleanup, etc.
        /// </summary>
        Disconnection
    }

    /// <summary>
    /// Interface Plugin Service. One or more interfaces can be used.
    /// </summary>
    public enum PluginService
    {
        /// <summary>
        /// Used for SMTP service
        /// </summary>
        SMTP = 1,

        /// <summary>
        /// Used for POP3 service
        /// </summary>
        POP3 = 2,

        /// <summary>
        /// Used for IMAP service
        /// </summary>
        IMAP = 4,

        /// <summary>
        /// Used for IM service
        /// </summary>
        IM = 8
    }

    /// <summary>
    /// Plugin response code enumeration
    /// </summary>
    public enum PluginResponse
    {
        /// <summary>
        /// Do nothing response
        /// </summary>
        Nothing = 0,

        /// <summary>
        /// Plugin confirms to Continue processing
        /// </summary>
        Continue,

        /// <summary>
        /// Plugin requires the service to disconnect
        /// </summary>
        Disconnect,

        /// <summary>
        /// Plugin requires the service to disconnect with error
        /// </summary>
        DisconnectWithError
    }

    /// --------------------------------------------------------------------
    /// Project	 : ServerLib
    /// Class	 : IServicePlugin
    /// Inherits : None.
    /// --------------------------------------------------------------------
    /// <summary>
    /// Interface class for application plugin libraries
    /// </summary>
    /// <authorname>Rob Kennedy</authorname>
    /// <remarks></remarks>
    /// --------------------------------------------------------------------
    public interface IServicePlugin
    {
        /// <summary>
        /// Gets the plugin library title
        /// </summary>
        string Name 
        { 
            get; 
        }

        /// <summary>
        /// Gets the plugin library key
        /// </summary>
        string Key 
        { 
            get; 
        }

        /// <summary>
        /// Gets or sets the Plugin library Type code
        /// </summary>
        PluginType Type 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets the error code returned by the plugin library
        /// </summary>
        int ErrorCode 
        { 
            get; 
        }

        /// <summary>
        /// Gets the error message returned by the plugin library
        /// </summary>
        string ErrorMessage 
        { 
            get; 
        }

        /// <summary>
        /// Gets or sets the services that use the plugin library
        /// </summary>
        List<PluginService> Services 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Gets or sets a collection of unique plugin specific attribute settings
        /// </summary>
        List<PluginAttribute> Attributes 
        { 
            get; 
            set; 
        }

        /// <summary>
        /// Executes the plugin library code and returns a response code
        /// </summary>
        /// <param name="context">Plugin context object containing context information</param>
        /// <returns>Returns a PluginResponse code for an appropriate service action</returns>
        PluginResponse DoAction(IServicePluginContext context);
    }
}